import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useMappingStore = defineStore('mapping', () => {
  const mysqlMapping = ref([
    {
      "typeReg": "int\\w+",
      "startWith": "int",
      "javaType": "Integer"
    },
    {
      "typeReg": "varchar(\\d+)",
      "startWith": "varchar",
      "javaType": "String"
    },
    {
      "typeReg": "char(\\d+)",
      "startWith": "char",
      "javaType": "String"
    },
    {
      "typeReg": "float\\w+",
      "startWith": "float",
      "javaType": "Float"
    },
    {
      "typeReg": "double\\w+",
      "startWith": "double",
      "javaType": "Double"
    },
    {
      "typeReg": "date",
      "startWith": "date",
      "javaType": "LocalDate"
    },
    {
      "typeReg": "datetime",
      "startWith": "datetime",
      "javaType": "LocalDateTime"
    },
    {
      "typeReg": "tinyint",
      "startWith": "tinyint",
      "javaType": "Byte"
    },
    {
      "typeReg": "smallint",
      "startWith": "smallint",
      "javaType": "Short"
    },
    {
      "typeReg": "bigint",
      "startWith": "bigint",
      "javaType": "Long"
    }
  ])
  const oracleMapping = ref([
    {
      "typeReg": "NUMBER\\((\\d+),\\d+\\)",
      "startWith": "NUMBER",
      "javaType": "BigDecimal"
    },
    {
      "typeReg": "NUMBER\\(\\d+\\)",
      "startWith": "NUMBER",
      "javaType": "Long"
    },
    {
      "typeReg": "VARCHAR2(\\d+)",
      "startWith": "VARCHAR2",
      "javaType": "String"
    },
    {
      "typeReg": "CHAR(\\d+)",
      "startWith": "CHAR",
      "javaType": "String"
    },
    {
      "typeReg": "DATE",
      "startWith": "DATE",
      "javaType": "LocalDate"
    },
    {
      "typeReg": "TIMESTAMP",
      "startWith": "TIMESTAMP",
      "javaType": "LocalDateTime"
    },
    {
      "typeReg": "CLOB",
      "startWith": "CLOB",
      "javaType": "java.sql.Clob"
    },
    {
      "typeReg": "BLOB",
      "startWith": "BLOB",
      "javaType": "java.sql.Blob"
    }
  ])
  const postgresqlMapping = ref([
    {
      "typeReg": "integer",
      "startWith": "integer",
      "javaType": "Integer"
    },
    {
      "typeReg": "bigint",
      "startWith": "bigint",
      "javaType": "Long"
    },
    {
      "typeReg": "varchar(\\d+)",
      "startWith": "varchar",
      "javaType": "String"
    },
    {
      "typeReg": "char(\\d+)",
      "startWith": "char",
      "javaType": "String"
    },
    {
      "typeReg": "float\\d+",
      "startWith": "float",
      "javaType": "Float"
    },
    {
      "typeReg": "double precision",
      "startWith": "double",
      "javaType": "Double"
    },
    {
      "typeReg": "date",
      "startWith": "date",
      "javaType": "LocalDate"
    },
    {
      "typeReg": "timestamp",
      "startWith": "timestamp",
      "javaType": "LocalDateTime"
    },
    {
      "typeReg": "text",
      "startWith": "text",
      "javaType": "String"
    }
  ])
  const mapping = ref({
    mysql: mysqlMapping.value,
    oracle: oracleMapping.value,
    postgresql: postgresqlMapping.value
  })
  const refreshMapping = (type, mapping) => {
    if (type === 'mysql') {
      mysqlMapping.value = mapping
    }
    if (type ==='oracle') {
      oracleMapping.value = mapping
    }
    if (type ==='postgresql') {
      postgresqlMapping.value = mapping
    }
  }
  return {
    mysqlMapping,
    oracleMapping,
    postgresqlMapping,
    mapping,
    refreshMapping
  }
}, {
  persist: true
})
